<?php

namespace app\common\components;
require_once dirname(__DIR__) . DS . 'library' . DS . 'HTMLPurifier'. DS .'HTMLPurifier.auto.php';

/**
 * 过滤html
 * Class Purifier
 * @package app\common\components
 */
class Purifier
{
    protected $_htmlPurifier = null;

    public function __construct($options = null)
    {
        $config = \HTMLPurifier_Config::createDefault();
        $config->set('Core.Encoding', 'UTF-8');
        $config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
        if(!is_null($options)){
            foreach($options as $option){
                $config->set($option[0], $option[1], $option[2]);
            }
        }
        $this->_htmlPurifier = new \HTMLPurifier($config);
    }

    public function filter($value)
    {
        return $this->_htmlPurifier->purify($value);
    }


}